import vue from '@vitejs/plugin-vue'
import jsx from '@vitejs/plugin-vue-jsx'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
  if (command === 'serve') {
    return {
      plugins: [vue()],
    }
  }

  if (command === 'build') {
    return {
      plugins: [vue(), jsx(), dts({
        entryRoot: 'src',
        logLevel: 'error',
      })],
      build: {
        lib: {
          entry: './src/magic.ts',
          formats: ['es'],
          fileName: () => 'material.js',
        },
        rollupOptions: {
          output: {
            assetFileNames: 'material.[ext]',
          },
        },
      },
      resolve: {
        alias: {
          vue: 'https://esm.sh/vue',
          'element-plus': 'https://esm.sh/element-plus',
        },
      },
    }
  }
})
